var express = require('express')
var router = express.Router();

router.post('/post/save/fileUpload.do',function(req,res,next){
  req.busboy.on('file', function (fieldname, file, filename) {
      console.log("Uploadingd: " + filename); 
      console.log(file);
      var fs = require('fs');
      fstream = fs.createWriteStream(__dirname + '/files/' + filename);
      file.pipe(fstream);
      fstream.on('close', function () {
          res.set('Content-Type','text/html')
          res.send({
             "resultCode": 0, //0为成功
             "resultMsg":"XXX", //错误信息
             "result":{
                 url:'/'+filename
             }
          })
          
      });
  });
  req.busboy.on('field',function(key,value,keyTruncated,valueTruncated){
    
    console.log(key,value,keyTruncated,valueTruncated);
  
  })
  req.pipe(req.busboy);  
})


module.exports = router